package com.zprmb.udzt.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.ConnectivityManager;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.tencent.smtt.export.external.interfaces.SslErrorHandler;
import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
import com.zprmb.udzt.BbtApplication;
import com.zprmb.udzt.LoginActivity;
import com.zprmb.udzt.MainActivity;
import com.zprmb.udzt.MainActivity2;
import com.zprmb.udzt.R;
import com.zprmb.udzt.Set_tr_pw;
import com.zprmb.udzt.V6DetailsActivity;
import com.zprmb.udzt.ll.BaseHelper;
import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.MySharePreferenceUtil;
import com.zprmb.udzt.util.VolleryUtil;
import com.zprmb.udzt.view.WebViewDialog;

import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
//import android.webkit.JavascriptInterface;
//import android.webkit.SslErrorHandler;
//import android.webkit.WebChromeClient;
//import android.webkit.WebSettings;
//import android.webkit.WebView;
//import android.webkit.WebViewClient;


@SuppressLint("SetJavaScriptEnabled")
public class WebViewActivity2 extends Activity {

    private ImageView iv_v4_web_back;
    private TextView tv_v4_web_title;
    private String title;
    private String ref = "";
    private String url;
    private WebViewDialog dialog;
    private WebView v4_webview;
    private ImageView img_share;
    private RelativeLayout rl_back;
    private ProgressBar bar;
    private boolean back = false;
    Map<String, String> extraHeaders;
    private SharedPreferences sha;
    private View title_view;
    int flag;

    private ImageView iv_v4_nonetwork;
    private View web_head_view;
private View title_view_new;
    public boolean network() {
        boolean flag = false;

        //得到网络连接信息
        ConnectivityManager manager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
        //去进行判断网络是否连接
        if (manager.getActiveNetworkInfo() != null) {
            flag = manager.getActiveNetworkInfo().isAvailable();
        }

        return flag;

    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setImmersionStatus();
        setContentView(R.layout.activity_webview3);
        BbtApplication.getInstance().addActvity(this);
        iv_v4_nonetwork = (ImageView) findViewById(R.id.iv_v4_nonetwork);
        v4_webview = (WebView) findViewById(R.id.v4_webview);
        v4_webview.setVisibility(View.VISIBLE);
//        MySharePreferenceUtil.put(WebViewActivity2.this, "intentflag", "2");
        Intent intent = getIntent();
        title = intent.getStringExtra("title");
//        url = intent.getStringExtra("url");
        url = (String) MySharePreferenceUtil.get(WebViewActivity2.this, "url", "");
//        ref = getShare().getString("usercode", "");
//		setgoback(this);
        dialog = new WebViewDialog(this);
//        Log.e("webview", url);
        token = (String) MySharePreferenceUtil.get(WebViewActivity2.this, "mytoken", "");
        MySharePreferenceUtil.remove(WebViewActivity2.this,"intentflag");
//        Toast.makeText(V6_Finger_Check_NewActivity.this, "233", Toast.LENGTH_SHORT).show();

        title_view_new=findViewById(R.id.title_view_new);
        title_view_new.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                WebViewActivity2.this.finish();
            }
        });
        try {
            token = URLEncoder.encode(token, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        // url = "account/invest/8F759CC2-65DB-11E5-AE96-5254002EAABD/contract";
        sha = getSharedPreferences("config", MODE_PRIVATE);
        flag = getIntent().getIntExtra("flag", 0);
        initView();
//        V6_Finger_Check_NewActivity.instance.finish();
        if (!network()) {
            iv_v4_nonetwork.setVisibility(View.VISIBLE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView

            v4_webview.setVisibility(View.GONE);
            title_view.setVisibility(View.VISIBLE);
            img_share.setVisibility(View.GONE);
            web_head_view.setVisibility(View.GONE);
        } else {
            iv_v4_nonetwork.setVisibility(View.GONE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView

            v4_webview.setVisibility(View.VISIBLE);
            title_view.setVisibility(View.GONE);
            web_head_view.setVisibility(View.VISIBLE);
            initData();

        }

    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        BbtApplication.getInstance().removeActvity(this);
    }

    String token;

    @Override
    protected void onResume() {


        // TODO Auto-generated method stub
        super.onResume();
        // v4_webview.loadUrl("http://192.168.20.29:8080"+"/landing/reward?app=true&token="+getToken());
        if (flag == 1) {
//			 v4_webview.loadUrl("http://192.168.40.154:8085/landing/mNationalDay2016?app=true");
            // v4_webview.loadUrl(Constant.URL+"/h5/expIntro?app=true");
//v4_webview.loadUrl("file:///android_asset/Untitled1.html");
            v4_webview.loadUrl(url + "&token=" + token, extraHeaders);
        } else {
            v4_webview.loadUrl(Constant.URL + url + token, extraHeaders);
            Log.e("title_url", Constant.URL + url + token);
        }

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == KeyEvent.KEYCODE_BACK) {

         /*   Intent intent = new Intent(WebViewActivity2.this, MainActivity2.class);
            startActivity(intent);
            overridePendingTransition(R.anim.in_from_left,
                    R.anim.out_to_right);*/
            WebViewActivity2.this.finish();
//            WebViewActivity2.this.finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    private boolean loadError = false;

    private void initData() {
        extraHeaders = new HashMap<String, String>();
        extraHeaders.put("token", token);
        v4_webview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) {


                    back = true;

//                     Log.e("myurl", url+"");
                    if (url.contains("?")) {
                        url = url + "&app=true&appversion=true&token=" + token;

                    } else {
                        url = url + "?app=true&appversion=true&token=" + token;

                    }
                    view.loadUrl(url, extraHeaders);
                    return true;
                }
                // else if(url.indexOf("tel")==0){
//				 view.loadUrl(url,extraHeaders);
                // return true;
                // }
                // view.loadUrl(Constant.URL_NEW+url,extraHeaders);
                // view.loadUrl("http://docs.google.com/gview?embedded=true&url=http://www.navicat.com.cn/manual/pdf_manual/cn/navicat/rv_manual/rviewer_cs.pdf");
                return true;
            }

            //			public void onReceivedSslError(WebView view,
//					SslErrorHandler handler, SslError error) {
//				// super.onReceivedSslError(view, handler, error);
//				handler.proceed();
//			}
            @Override
            public void onReceivedSslError(WebView arg0, SslErrorHandler arg1,
                                           com.tencent.smtt.export.external.interfaces.SslError arg2) {
                // TODO Auto-generated method stub
//				super.onReceivedSslError(arg0, arg1, arg2);
                arg1.proceed();
            }

            @Override
            public void onReceivedError(WebView webView, int i, String s, String s1) {
                loadError = true;
                iv_v4_nonetwork.setVisibility(View.VISIBLE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView
                rl_back.setVisibility(View.GONE);
                v4_webview.setVisibility(View.GONE);
                title_view.setVisibility(View.VISIBLE);
                img_share.setVisibility(View.GONE);
                web_head_view.setVisibility(View.GONE);
            }

            @Override
            public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
                iv_v4_nonetwork.setVisibility(View.VISIBLE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView
                rl_back.setVisibility(View.GONE);
                v4_webview.setVisibility(View.GONE);
                title_view.setVisibility(View.VISIBLE);
                img_share.setVisibility(View.GONE);
                web_head_view.setVisibility(View.GONE);
            }
        });
        v4_webview.clearCache(true);
        v4_webview.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                Log.e("进度", newProgress + "");
                if (newProgress == 100) {
                    dialog.dismiss();
                } else {
                    if (dialog.isShowing() == false & !WebViewActivity2.this.isFinishing()) {
                        dialog.show();
                    }

                }
                super.onProgressChanged(view, newProgress);
            }


        });
        // 重新设置websettings WebSettings s = wb.getSettings();
        // s.setBuiltInZoomControls(true);
        // s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        v4_webview.getSettings().setUseWideViewPort(true);
        v4_webview.getSettings().setLoadWithOverviewMode(true);
        v4_webview.getSettings().setSavePassword(true);
        v4_webview.getSettings().setSaveFormData(true);
        v4_webview.getSettings().setJavaScriptEnabled(true);
        // enable navigator.geolocation
        v4_webview.getSettings().setGeolocationEnabled(true);
        v4_webview.getSettings().setGeolocationDatabasePath(
                "/data/data/org.itri.html5webview/databases/");
        // enable Web Storage: localStorage, sessionStorage
//		v4_webview.getSettings().setDomStorageEnabled(true);
        v4_webview.requestFocus();
        v4_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        // v4_webview.setScrollBarStyle(0);
        String ua = v4_webview.getSettings().getUserAgentString();
        v4_webview.getSettings().setUserAgentString(
                ua + "; " + "rmbbox_android");
        v4_webview.addJavascriptInterface(new JsInterfaces(this),
                "AndroidWebView");
        v4_webview.getSettings().setBuiltInZoomControls(true);
        v4_webview.getSettings().setLayoutAlgorithm(
                WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        v4_webview.getSettings().setDomStorageEnabled(true);
        // Set cache size to 8 mb by default. should be more than enough
        v4_webview.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
        // This next one is crazy. It's the DEFAULT location for your app's
        // cache
        // But it didn't work for me without this line.
        // UPDATE: no hardcoded path. Thanks to Kevin Hawkins
        String appCachePath = getApplicationContext().getCacheDir()
                .getAbsolutePath();

        v4_webview.getSettings().setAllowFileAccess(true);
        v4_webview.getSettings().setAppCacheEnabled(true);
        v4_webview.getSettings().setJavaScriptEnabled(true);
        v4_webview.getSettings().setAppCachePath(appCachePath);
        v4_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        v4_webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//		v4_webview.getSettings().setSupportZoom(true);
        v4_webview.getSettings().setDefaultTextEncodingName("utf-8");
        if (v4_webview.getX5WebViewExtension() != null) {

            v4_webview.getX5WebViewExtension().setVerticalTrackDrawable(null);
        }

        // v4_webview.loadUrl("http://preview.rmbbox.com:8082/v3/product/dqDescribe?flagFresh=false&type=FIXED_DEPOSIT_3");

        // if(title.equals("了解智投宝")){
        // v4_webview.loadUrl(Constant.URL+url);
        // }
        // else{
        // v4_webview.loadUrl(Constant.URL+url);
        // // v4_webview.loadUrl("http://192.168.2.12:8088/h5/help?app=true");
        // }
    }

    private class JsInterfaces {
        private Context mContext;

        public JsInterfaces(Context context) {
            this.mContext = context;
        }

        // 在js中调用window.AndroidWebView.showInfoFromJs(name)，便会触发此方法。
        @JavascriptInterface
        public void pleaseLogin(String name) {
         /*   Intent intent = new Intent(WebViewActivity.this,
                    V6LoginActivity.class);
            intent.putExtra("close", 1);
            intent.putExtra("web", 1);
            startActivityForResult(intent, 1);*/
       /*     mpleaseLogin(WebViewActivity2.this, 1, 1, 0);
            WebViewActivity2.this.finish();
            Editor editor = sha.edit();
            editor.putString("url", url);
            editor.commit();*/
        }

        @JavascriptInterface
        public void showInfoFromJs(String name) {

            initshare();
        }

        @JavascriptInterface
        public void finishActivity() {
//Log.e("help", "关闭当前页面");
//            WebViewActivity2.this.finish();
            Intent intent = new Intent(WebViewActivity2.this, MainActivity.class);
            startActivity(intent);
//            WebViewActivity2.this.finish();
        }

        @JavascriptInterface
        public void toproduct(String[] list) {

            // Toast.makeText(Active_Webview.this, list.toString(),
            // 2000).show();

            Intent intent = new Intent(WebViewActivity2.this,
                    V6DetailsActivity.class);
            intent.putExtra("flag", Boolean.parseBoolean(list[0]));
            intent.putExtra("name", list[1]);
            intent.putExtra("type", list[2]);
            intent.putExtra("id", list[3]);
            intent.putExtra("isred", list[4]);

            startActivity(intent);
        }

        @JavascriptInterface
        public void jsshare2(String sharelink, String description, String title, String imageurl) {
//			Toast.makeText(V4WebViewActivity.this, sharelink+sharelink+title, 2000).show();
            if (sharelink.length() > 1) {
                if (ref.equals("")) {


                } else {
                    sharelink = sharelink + "?ref=" + ref;

                }
                Message message = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("title", title);
                bundle.putString("sharelink", sharelink);
                bundle.putString("description", description);
                bundle.putString("imageurl", imageurl);
                message.setData(bundle);//bundle传值，耗时，效率低
                handler.sendMessage(message);//发送message信息
                message.what = 1;//标志是哪个线程传数据

            }
        }



        @JavascriptInterface
        public void jsshare(String sharelink, String description, String title) {

            if (sharelink.length() > 1) {
                if (ref.equals("")) {


                } else {
                    sharelink = sharelink + "?ref=" + ref;

                }
                Message message = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("title", title);
                bundle.putString("sharelink", sharelink);
                bundle.putString("description", description);
                message.setData(bundle);//bundle传值，耗时，效率低
                handler.sendMessage(message);//发送message信息
                message.what = 1;//标志是哪个线程传数据

            }
        }

        @JavascriptInterface
        public void Tel_phone(String phone) {
            BaseHelper.showDialog2(WebViewActivity2.this, "拨号", phone, 1);
        }

        @JavascriptInterface
        public void finish(int type) {

//            startActivity(new Intent(WebViewActivity2.this, MainActivity.class));
     /*       Intent intent = new Intent(WebViewActivity2.this, MainActivity2.class);
            startActivity(intent);
            WebViewActivity2.this.finish();*/
            Intent intent = new Intent(WebViewActivity2.this, MainActivity2.class);
            startActivity(intent);
            overridePendingTransition(R.anim.in_from_left,
                    R.anim.out_to_right);
            WebViewActivity2.this.finish();
        /*    if (type == 0) {
                WebViewActivity2.this.finish();
                return;

            }
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub

                    if (v4_webview.canGoBack()) {
                        v4_webview.goBack();
                    } else {
                        if (dialog != null) {


                        }
                        Intent intent = new Intent();
                        setResult(1, intent);
                        WebViewActivity2.this.finish();
                    }
                }
            });*/


        }

        @JavascriptInterface
        public void settab(int i) {

            Editor ed = sha.edit();
            ed.putInt("tab", i);
            ed.commit();
            Intent intent = new Intent(WebViewActivity2.this,
                    MainActivity.class);
            intent.putExtra("licai", 1);
            startActivity(intent);
        }

        @JavascriptInterface
        public void setTitle(String title) {
            tv_v4_web_title.setText(title);

        }

        @JavascriptInterface
        public void setactivity(String activity) {


            Intent intent;
            try {
                intent = new Intent(WebViewActivity2.this,
                        Class.forName(activity));
                startActivity(intent);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        @JavascriptInterface
        public void addmoney() {
            verifuser("1");
        }

        public void sendInfoToJs(View view) {
            String msg = token;
            Log.e("web", "调用");
            // 调用js中的函数：showInfoFromJava(msg)

        }
    }

    public void shareforjs(String sharelink, String description, String title) {
        if (ref.equals("")) {


        } else {
            sharelink = sharelink + "?ref=" + ref;

        }
//        share(WebViewActivity2.this, description, title, description, "");
    }

    private void initshare() {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                Log.e("invate", jsonObject.toString());
                if (jsonObject.optInt("success") == 1) {
                    JSONObject json = jsonObject.optJSONObject("data");
                    String linkurl = "";
                    if (ref.equals("")) {
                        linkurl = json.optString("linkUrl");

                    } else {
                        linkurl = json.optString("linkUrl") + "?ref=" + ref;

                    }


//                    share(WebViewActivity2.this, json.optString("description"), json.optString("title"), linkurl, "");
                } else {

                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
                // TODO Auto-generated method stub
                iv_v4_nonetwork.setVisibility(View.VISIBLE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView

                v4_webview.setVisibility(View.GONE);
                title_view.setVisibility(View.VISIBLE);
                img_share.setVisibility(View.GONE);
                web_head_view.setVisibility(View.GONE);
            }
        };
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(true);
        volleryUtil.execute(WebViewActivity2.this, Constant.URL + "/api/shareProductContent/inviteFriend/inviteFriend", "");
    }

    private void setImmersionStatus() {
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

    Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 1) {
//                share(WebViewActivity2.this, msg.getData().getString("description"), msg.getData().getString("title"), msg.getData().getString("sharelink"), msg.getData().getString("imageurl"));
            }


        }

        ;
    };

    private void verifuser(final String who) {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    JSONObject json = jsonObject.optJSONObject("data");

                    if (json.optBoolean("nameAuth") && json.optBoolean("isBindCard")) {
                        if (who.equals("1")) {
//							
//                            Intent intent = new Intent(WebViewActivity2.this, V4AddMoneySActiviy.class);
//                            startActivity(intent);
                        } else {
                            if (json.optBoolean("payPass")) {

                            } else {
                                Intent intent = new Intent(WebViewActivity2.this, Set_tr_pw.class);
                                startActivity(intent);
                            }
                        }
                    } else {

//							if (!json.optBoolean("nameAuth")) {
//								Intent intent = new Intent(AssetsActivity.this,Real_Name.class);
//								startActivity(intent);
//								return;
//							}
                        if (json.optString("bankMobileStatus") != null && !json.optString("bankMobileStatus").equals("") && json.optString("bankMobileStatus").equals("WAIT_CHECK")) {

                        }
                        if (!json.optBoolean("isBindCard")) {
//								!json.optBoolean("isBindCard")

                        }

                    }
                } else {
                    if (jsonObject.optString("comment").equals("please login")) {
                        Intent intent = new Intent(WebViewActivity2.this,
                                LoginActivity.class);
                        intent.putExtra("close", 1);
                        startActivity(intent);
                    }
                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
                // TODO Auto-generated method stub
                iv_v4_nonetwork.setVisibility(View.VISIBLE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView

                v4_webview.setVisibility(View.GONE);
                title_view.setVisibility(View.VISIBLE);
                img_share.setVisibility(View.GONE);
                web_head_view.setVisibility(View.GONE);
            }
        };
        volleryUtil.setRequestMethod(0);
        volleryUtil.setHeaders("token", token);
        volleryUtil.setShow(true);
        volleryUtil.execute(this, Constant.URL + "/api/v5/user/userInfo", "");
    }

    private void initView() {
        iv_v4_web_back = (ImageView) findViewById(R.id.img_back);
        rl_back = (RelativeLayout) findViewById(R.id.rl_back);
        bar = (ProgressBar) findViewById(R.id.myProgressBar);
        title_view = (View) findViewById(R.id.title_view);
        img_share = (ImageView) findViewById(R.id.img_share);

        //titleview
        web_head_view = findViewById(R.id.web_head_view);

        rl_back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Log.e("back", "点击");
                if (getIntent().getIntExtra("splash", 0) == 1) {
                    Intent intent = new Intent(WebViewActivity2.this, MainActivity.class);
                    startActivity(intent);
                } else {
                    if (v4_webview.canGoBack()) {
                        v4_webview.goBack();
                    } else {

                        WebViewActivity2.this.finish();
                    }
                }

            }
        });
        iv_v4_web_back.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {

                if (getIntent().getIntExtra("splash", 0) == 1) {
                    Intent intent = new Intent(WebViewActivity2.this, MainActivity.class);
                    startActivity(intent);
                } else {

                    if (v4_webview.canGoBack()) {
                        v4_webview.goBack();
                    } else {
                        WebViewActivity2.this.finish();
                    }
                }


            }
        });
        tv_v4_web_title = (TextView) findViewById(R.id.tv_title);
        tv_v4_web_title.setText(title);
        if (getIntent().getIntExtra("share", 0) == 1) {
            img_share.setVisibility(View.GONE);
        }
        tv_v4_web_title.getPaint().setFakeBoldText(true);
        if (getIntent().getIntExtra("titleview", 0) == 1) {
            title_view.setVisibility(View.GONE);
            web_head_view.setVisibility(View.VISIBLE);
        } else {
            title_view.setVisibility(View.GONE);
            web_head_view.setVisibility(View.VISIBLE);
        }
        v4_webview = (WebView) findViewById(R.id.v4_webview);
        iv_v4_nonetwork.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
//                v4_webview.reload();
//                initData();
                if (!network()) {
                    iv_v4_nonetwork.setVisibility(View.VISIBLE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView

                    v4_webview.setVisibility(View.GONE);
                    title_view.setVisibility(View.VISIBLE);
                    img_share.setVisibility(View.GONE);
                    web_head_view.setVisibility(View.GONE);
                    rl_back.setVisibility(View.GONE);
                    Toast.makeText(WebViewActivity2.this, "当前无网络", Toast.LENGTH_SHORT).show();
                } else {
                    iv_v4_nonetwork.setVisibility(View.GONE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView

                    v4_webview.setVisibility(View.VISIBLE);
                    title_view.setVisibility(View.GONE);
                    web_head_view.setVisibility(View.VISIBLE);
//                    initData();
                    v4_webview.reload();
                    initData();
                    rl_back.setVisibility(View.VISIBLE);
                }
            }
        });
    }
}
